package com.chapter13.homework;

import java.util.Scanner;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class HomeWork02 {
    public static void main(String[] args) {
        try {
            A();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static void A() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名（长度最少为两位，最多四位）：");
        String name = scanner.next();
        if (!(name.length() >= 2 && name.length() <= 4)) {
            throw new RuntimeException("用户名长度错误");
        }
        System.out.println("请输入密码（长度为6位并且是数字）：");
        String pwd = scanner.next();
        char[] p = pwd.toCharArray();
        for (int i = 0; i < p.length; i++) {
            if (!(p.length == 6 && p[i] >= '0' && p[i] <= '9')) {
                throw new RuntimeException("密码输入错误");
            }
        }
        System.out.println("请输入邮箱：");
        String email = scanner.next();
        StringBuffer sb1 = new StringBuffer(email);
        if (!(sb1.indexOf("@") > -1 && sb1.indexOf("@") < sb1.indexOf("."))) {
            throw new RuntimeException("邮箱输入错误");
        }

    }
}
